package com.data.center.controller;

import com.data.center.dictionary.AdminDivisionLevel;
import com.data.center.dictionary.AdminDivisionStatus;
import com.data.center.dto.TestDto;
import com.data.center.entity.AdminDivision;
import com.data.center.exception.ResultBody;
import com.data.center.service.AdminDivisionService;
import com.data.center.util.DateTimeUtils;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

@RestController
@RequestMapping("/test")
@Slf4j
public class testController {

    @Autowired
    AdminDivisionService adminDivisionService;

    @PostMapping("/t")
    public String test() {
        log.info("test");

        return "success";
    }

    @PostMapping("/hot")
    public String hot() {
        log.info("test");

        return "cold success";
    }

    @PostMapping("/exception")
    public String exception() {
        AdminDivision adminDivision = new AdminDivision();

        adminDivision.setId("123123123123123");
        adminDivision.setCode("00001000");
        adminDivision.setName("测试");
        adminDivision.setLevel(Integer.parseInt(AdminDivisionLevel.PROVINCE.getKey()));
        adminDivision.setParent("000");
        adminDivision.setStatus(Integer.parseInt(AdminDivisionStatus.IN_EFFECT.getKey()));
        adminDivision.setEffectiveDate(DateTimeUtils.getCurrentDateTime());
        adminDivision.setExpiryDate(DateTimeUtils.getCurrentDateTime());

        adminDivisionService.createAdminDivision(adminDivision);
        return "insert success";
    }

    @PostMapping("/incrementalInformation")
    public ResultBody incrementalInformation(@RequestBody TestDto testDto) {
        log.info("testDto" + testDto + testDto.getKeyWithAdditionalInformation());
        return ResultBody.success();
    }

}
